/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package maxent.mr.writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;

/**
 *
 * @author hadoop
 */
public class ArrayStringWritable implements Writable{

    private HashSet<String> tokens = new HashSet();

    public ArrayStringWritable() {
    }

    public ArrayStringWritable(Iterable<Text> words){

        for(Text word: words){            
           tokens.add(word.toString());
        }
    }

   

    @Override
    public String toString() {        

        String output = "";

        for(String word : tokens){
            
            output += (word+" ");
        }

        return output;
        
    }

    @Override
    public void write(DataOutput out) throws IOException {
        for (String word : tokens){

            Text text = new Text(word);
            text.write(out);
        }
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        for(String word : tokens){
            Text text = new Text(word);
            text.readFields(in);
        }
    }

}
